#include <wait.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>

static void charactatime(char *);

int main(){
    pid_t pid;
    if((pid = fork()) < 0){
        printf("fork error!\n");
        exit(0);
    }else if(pid == 0){
        charactatime("output from child, output from child, output from child\n");
    }else{
        charactatime("output from parent, output from parent, output from parent\n");
    }

    exit(0);
}

static void charactatime(char *str){
    char *ptr;
    int c;

    //设置stdout为全缓冲的，这样对于标准库函数的写操作相当于直接调用write
    setbuf(stdout, NULL);
    for(ptr = str; (c = *ptr++) != '\0';){
        putc(c, stdout);
    }
}